﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FinanceGoldPointDal.Utils;

namespace FinancialDesktop
{
  /// <summary>
  /// Interaction logic for MainWindow.xaml
  /// </summary>
  public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
     new FinanceGoldPointDal.Utils.SymbolsGetter().UpdateSymbolsInDb("*.MI");
    }

    private void buttonVediDato_Click(object sender, RoutedEventArgs e)
    {
      if (string.IsNullOrEmpty(textBoxCode.Text)) return;

        var util = new SymbolsGetter();
        if (!checkFullData.IsChecked.Value)
        {

          new MaasGetDatiSimbolo().getdatiSimbolo(textBoxCode.Text);

          var res = util.GetQuotes(new string[] { textBoxCode.Text }, 2);
          dataGrid1.ItemsSource = res;
        }
        else
        {
          var result = util.GetFullQuotes(new string[] { textBoxCode.Text });

          if (result.HasErrors)
          {
            MessageBox.Show("Errori :" + result.Eccezione.Message);
          }
          else
            dataGrid1.ItemsSource = result.Dati;
        }
      

    }

    private void buttonMonitora_Click(object sender, RoutedEventArgs e)
    {
      try
      {
        labelMsg.Content = " Start : " + DateTime.Now.ToString("hh:MM:ss");

        new MaasGetDatiSimbolo().controllaSimboliBuoni();

        labelMsg.Content = " End  : " + DateTime.Now.ToString("hh:MM:ss");
        MessageBox.Show("Controllo Simboli buoni finito");

      }
      catch (Exception ex)
      {
        MessageBox.Show("Errori :" + ex.Message);
      }
    }

    private void buttonStatBase_Click(object sender, RoutedEventArgs e)
    {
      var util = new GetterSymbolStatsBase();
      util.getStatBaseSimbolo(textBoxCode.Text);


    }

    private void buttonCreaStatsbaseDb_Click(object sender, RoutedEventArgs e)
    {
      var util = new GetterSymbolStatsBase();
      util.aggiornaStatisticheSimbooliDB();
    }
  }
}
